<template>
  <div class="app-container">
    <el-form :inline="true" :model="queryParams" class="demo-form-inline">
      <el-form-item label="产品名称">
        <el-input v-model="queryParams.name" placeholder="产品名称" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
        <el-button type="primary" @click="reset">重置</el-button>
      </el-form-item>
    </el-form>
    <el-button type="primary" style="margin-bottom: 15px;" @click="onInsert">新增</el-button>
    <el-table v-loading="listLoading" :data="list" element-loading-text="Loading" border fit highlight-current-row>
      <el-table-column align="center" label="产品id" prop="id" width="95" />
      <el-table-column label="产品名称" align="center" prop="name" />
      <el-table-column label="产品描述" align="center" prop="description" />
      <el-table-column label="产品封面" align="center" prop="cover">
        <template slot-scope="scope">
          <img :src="scope.row.cover" width="100" height="100">
        </template>
      </el-table-column>
      <el-table-column label="产品内容图" align="center" prop="picture">
        <template slot-scope="scope">
          <img :src="scope.row.picture" width="100" height="100">
        </template>
      </el-table-column>

      <el-table-column label="日利率" align="center" prop="interestRate" />

      <el-table-column label="持有时长" align="center" prop="holdTime" />
      <el-table-column label="是否开放" align="center" prop="isRookiePro">
        <template slot-scope="scope">
          {{ scope.row.open == 1 ? '已开放' : '未开放' }}
        </template>
      </el-table-column>
      <el-table-column label="理财类型" align="center" prop="isRookiePro">
        <template slot-scope="scope">
          {{ scope.row.type == 2 ? '活期' : scope.row.type == 1 ? '定期' : '' }}
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="isRookiePro">
        <template slot-scope="scope">
          {{ scope.row.status == 1 ? '上架' : '下架' }}
        </template>
      </el-table-column>
      <el-table-column label="排序" align="center" prop="sort" />

      <el-table-column label="最低购买金额" align="center" prop="minAmount" />
      <el-table-column label="最高金额" align="center" prop="maxAmount" />
      <el-table-column label="总限购金额" align="center" prop="sumLimitMoney" />
      <el-table-column label="复投金额" align="center" prop="reinvestAmount" />

      <el-table-column label="操作" align="center" width="250">
        <template slot-scope="scope">
          <el-button type="text" @click="handleZs(scope.row)">批量赠送</el-button>

          <el-button type="text" @click="handleShowInfo(scope.row)">编辑</el-button>
          <el-button type="text" @click="handleHistory(scope.row)">{{
            scope.row.status == 1 ? "下架" : "上架"
          }}</el-button>

        </template>
      </el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination :current-page.sync="queryParams.pageNum" :page-sizes="[10, 20, 30, 40]"
        :page-size.sync="queryParams.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"
        @size-change="fetchData" @current-change="fetchData" />
    </div>
    <showInfo ref="showInfo" />
    <add ref="add" />
    <zs ref="zs" />

  </div>
</template>

<script>
import showInfo from './showInfo.vue'
import add from './add.vue'
import zs from './zs.vue'
import { productPageList, dividendEnable } from '@/api/table'
export default {
  components: {
    showInfo,
    add,
    zs
  },
  data() {
    return {
      list: null,
      listLoading: true,
      total: 0,
      timer: null,
      statusOptions: [
        { label: '正常', value: '1' },
        { label: '禁用', value: '0' }
      ],
      sortByList: [
        { id: 'trx_balance', text: '余额' },
        { id: 'insurance_balance', text: '保险仓余额' },
        { id: 'fuel', text: 'wk余额' },
        { id: 'fix_insurance_balance', text: 'ai托管金额' }
      ],
      queryParams: {

        pageSize: 10,
        pageNum: 1,

        name: '',
      }
    }
  },
  created() {
    this.fetchData()
  },
  destroyed() { },
  methods: {

    handleTd(record, index) {
      console.log('....................')
      this.$refs.td.show(record, index)
    },
    handleBill(record) {
      this.$refs.children.show(record)
    },
    handleZS(record) {
      this.$refs.zs.show(record)

    },
    handleHistory(record) {
      this.$confirm(
        '此操作将' + (record.status == 1 ? '下架' : '上架') + ', 是否继续?',
        '提示',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      ).then(async () => {
        await dividendEnable({
          id: record.id,
          status: record.status == 1 ? 0 : 1
        })
        this.fetchData()
      })
    },
    handleC(record) {
      this.$refs.addC.show(record)
    },
    handleZs(record) {
      this.$refs.zs.show(record)
    },
    handleUser(record) {
      this.$refs.userComponents.show(record)
    },

    fetchData() {
      this.listLoading = true
      productPageList(this.queryParams).then((response) => {
        response.data.records.map((item) => {
          if (item.status === 1) {
            item.statusB = true
          } else {
            item.statusB = false
          }
          console.log(item.statusB)
        })
        this.list = response.data.records
        this.listLoading = false
        this.total = response.data.total
      })
    },
    handleShowInfo(e) {
      this.$refs.add.edit(e)
    },
    onSubmit() {
      this.queryParams.pageNum = 1
      this.fetchData()
    },
    reset() {
      this.queryParams = {
        pageSize: 10,
        pageNum: 1,

        name: '',
      }
      this.fetchData()
    },
    onInsert(record) {
      this.$refs.add.show(record)
    },
    handleEdit(e) {
      this.$refs.product.show(e)
    }
  }
}
</script>
